Skip to content

Conversation

@royle-vietnam
Copy link
Contributor

Pre-create the target column to avoid triggering compute() during update,
and perform a direct bulk data transfer from account_move to account_move_line.
This avoids ORM overhead, reduces heap rewrites, and prevents unnecessary
recomputation on 15M move lines.

Performance result:

  • Previous approach: ~2 hours
  • Optimized approach: ~15 minutes (~8x faster)

and bulk transferring invoice_date

Pre-create the target column to avoid triggering compute() during
update,
and perform a direct bulk data transfer from account_move to
account_move_line.
This avoids ORM overhead, reduces heap rewrites, and prevents
unnecessary
recomputation on 15M move lines.

Performance result:
- Previous approach: ~2 hours
- Optimized approach: ~15 minutes
(~8x faster)
@pedrobaeza pedrobaeza added this to the 17.0 milestone Dec 5, 2025
Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this improves the performance? Odoo already does a SQL for related fields with only one level of depth.

@royle-vietnam
Copy link
Contributor Author

Are you sure this improves the performance? Odoo already does a SQL for related fields with only one level of depth.

Yes, I'm aware that Odoo ORM already optimizes SQL for related fields with one level of depth.
However, the SQL generated by the ORM still includes all account.move records, including those with invoice_date IS NULL.

In my custom SQL, I explicitly exclude moves where invoice_date is NULL, which reduces the dataset before aggregation. This difference helps avoid unnecessary rows being processed and therefore improves performance in our specific case.

So the improvement does not come from bypassing the related field resolution, but from pruning irrelevant records earlier in the query.

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have proposed odoo/odoo#238812, but meanwhile, let's merge it.

@pedrobaeza pedrobaeza merged commit 3e483a4 into OCA:17.0 Dec 5, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants